package square;


import static org.junit.Assert.*;

import java.math.BigDecimal;

import org.junit.Before;
import org.junit.Test;

import dungeon.Level;
import dungeon.Position;

import border.Border;
import border.Wall;

public class RockTest {
	
	private static Rock rock1;
	private static Rock rock2;
	private static Direction direction1;
	private static Direction direction2;
	private static Direction direction3;

	@Before
	public void setUp() throws Exception {
		rock1 = new Rock();
		rock2 = new Rock();
		direction1 = Direction.NORTH;
		direction2 = Direction.EAST;
		direction3 = Direction.SOUTH;
	}
	
	@Test
	public void setTemperature_LegalCase(){
		Level<Square> l = new Level<Square>(5,5,0);
		Temperature temperature1 = new Temperature(4, TemperatureScale.CELCIUS);
		Temperature temperature2 = new Temperature(10, TemperatureScale.CELCIUS);
		NormalSquare nSquare1 = new NormalSquare(temperature1, new BigDecimal(0), false);
		NormalSquare nSquare2 = new NormalSquare(temperature2, new BigDecimal(0), false);
		Position pos1 = new Position(2,4,0);
		Position pos2 = new Position(3,4,0);
		Position pos3 = new Position(2,3,0);
		Position pos4 = new Position(3,3,0);
		l.addSquare(pos1, rock1);
		l.addSquare(pos2, rock2);
		l.addSquare(pos3, nSquare1);
		l.addSquare(pos4, nSquare2);
		rock1.setTemperature();
		rock2.setTemperature();
		assertEquals(rock1.getTemperature().getTemperatureValue(), 7, 1);
		assertEquals(rock2.getTemperature().getTemperatureValue(), 7, 1);
	}
	
	@Test
	public void removeBorder_NoRemovalCase(){
		Wall w = (Wall) rock1.getBorder(direction2);
		rock1.removeBorder(w);
		assertEquals(w, rock1.getBorder(direction2));
	}
	
	@Test
	public void removeBorder_RemovalCase(){
		Wall w = (Wall) rock1.getBorder(direction1);
		rock1.terminate();
		rock1.removeBorder(w);
		assertFalse(rock1.hasBorder(w));
		
	}
	
	@Test
	public void replaceBorderWith_TrueCase(){
		Wall w1 = (Wall) rock1.getBorder(direction3);
		Wall w2 = (Wall) rock2.getBorder(direction1);
		w1.replaceWith(w2);
		assertEquals(w2, rock1.getBorder(direction3));
	}
	@Test (expected = IllegalArgumentException.class)
	public void replaceBorderWith_IllegalCase(){
		Wall w1 = (Wall) rock1.getBorder(direction3);
		Border w2 = null;
		w1.replaceWith(w2);

	}


}
